<?php

class KeresesController extends Controller {

    public $layout = '//layouts/column1';

    /**
     * @return array action filters
     */
    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
            'postOnly + delete', // we only allow deletion via POST request
        );
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules() {
        return array(
            array('allow', // allow all users to perform 'index' and 'view' actions
                'actions' => array('index', 'keres'),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array(),
                'users' => array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions' => array(),
                'users' => array('admin'),
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }

    public function actionIndex() {
        $data = new KeresesForm();
        $data->minAr = 0;
        $data->maxAr = 0;
        $this->render('index', array(
            'data' => $data,
        ));
    }
    
    /**
     * Kereső függvény
     */
    public function actionKeres() {

        $data = new KeresesForm();
        if (isset($_GET['KeresesForm'])) {           
            $data->setAttributes($_GET['KeresesForm']);
        }       
        $crit = new CDbCriteria();
        if($_GET['BaseIngatlanJellemzo']['ID']){
            $crit->join = 'INNER JOIN ingatlan_has_ingatlan_jellmzo ON ingatlan_has_ingatlan_jellmzo.ingatlan_ID = ID';
            foreach ($_GET['BaseIngatlanJellemzo']['ID'] as $value) {
                $crit->addCondition('ingatlan_has_ingatlan_jellmzo.ingatlan_jellmzo_ID = '.$value);
            }         
        }
        $crit->addBetweenCondition('ar', $data->minAr, $data->maxAr);
        if($_GET['ing_tip']){
            $crit->addCondition('ingatlan_tipus_ID = '.$_GET['ing_tip']);
        }
        if($_GET['varos']){
            $crit->addCondition('varos_ID = '.$_GET['varos']);
        }
        $dataProvider = new CActiveDataProvider('Ingatlan', array(
            'criteria' => $crit,
                ));
        $this->render('index', array(
            'dataProvider' => $dataProvider,
            'data' => $data,
        ));
    }

}

?>
